package com.mew.chess.core.game.shbz;


import com.mew.chess.core.common.handler.ChessHandlerMapCmdType;
import com.mew.chess.core.common.handler.ChessPlayAnnotation;
import com.mew.chess.core.common.handler.ChessPlayHandler;
import com.mew.chess.core.game.shbz.game.ShbzGameManager;
import com.mew.chess.core.game.shbz.game.ShbzRoomManager;
import com.mew.chess.core.game.shbz.game.ShbzTableManager;
import com.mew.chess.core.game.shbz.game.common.FishTableUtil;
import com.mew.chess.core.game.shbz.game.common.FishUserBO;
import com.mew.chess.core.game.shbz.game.message.FishCMDMapType;
import com.mew.chess.core.game.shbz.game.message.request.SwitchCannonRequestMessage;
import com.mew.common.rest.bo.GameSession;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@ChessPlayAnnotation(ChessHandlerMapCmdType.ShbzSwitchCannon)
@Service
@Slf4j
public class ShbzSwitchCannonHandler implements ChessPlayHandler<SwitchCannonRequestMessage> {

    @Override
    public void handle(ZebraCommand<SwitchCannonRequestMessage> command, GameSession gameSession) {
        SwitchCannonRequestMessage message = command.getRequest();
        ShbzRoomManager roomManager = ShbzGameManager.getInstance().getController(gameSession.getRoomId());
        ShbzTableManager table = roomManager.getTableByUserId(gameSession.getUserId());
        FishUserBO fishUserBO = table.getOnlineUserMap().get(command.getUserId());
        fishUserBO.setCannonId(message.getCannonId());
        FishTableUtil.sendMsgByTable(table,message, FishCMDMapType.ShbzSwitchCannon.code(),0);
    }
}
